﻿using System;
using System.Collections.Generic;

namespace LeanEngine.Data.Linq.Language
{
    public class JoinToken : IQueryToken
    {
        #region Constructor Members

        public JoinToken()
        {
            this.JoinType = Language.JoinType.INNER;
            this.PredicateList = new List<IQueryToken>();
        }

        #endregion

        #region PropertyInfo Members

        public TableToken JoinedTable { get; set; }
        public JoinType JoinType { get; set; }
        public List<IQueryToken> PredicateList { get; set; }

        #endregion

        #region ILanguageToken Members

        public virtual string GetStatement()
        {
            var sql = this.JoinType.ToString() + " JOIN " + this.JoinedTable.Name + " " + this.JoinedTable.Alias + " ON ";
            foreach (var predicate in PredicateList)
            {
                sql += predicate.GetStatement() + " ";
            }

            return sql;
        }

        #endregion
    }

    public enum JoinType
    {
        INNER,
        LEFT,
        RIGHT
    }
}
